// Tests / Functions / Helpers

// th-math-power()
// ------------------------------

function th-math-power {

  @include th-assert(
    $describe: "Calculate power of 5 to 3."
  ){
    @include th-assert-expect {
      result: 125;
    }
    @include th-assert-actual {
      result: th-math-power(5, 3);
    }
  }

  @include th-assert(
    $describe: "Calculate power of 5 to 1."
  ){
    @include th-assert-expect {
      result: 5;
    }
    @include th-assert-actual {
      result: th-math-power(5, 1);
    }
  }

  @include th-assert(
    $describe: "Calculate power of -5 to 3."
  ){
    @include th-assert-expect {
      result: -125;
    }
    @include th-assert-actual {
      result: th-math-power(-5, 3);
    }
  }

}

// th-math-round-to()
// ------------------------------

function th-math-round-to {

  @include th-assert(
    $describe: "Round 5.0246 to 3 decimal places"
  ){
    @include th-assert-expect {
      result: 5.025;
    }
    @include th-assert-actual {
      result: th-math-round-to(5.0246, 3);
    }
  }

}

// th-map-set()
// ------------------------------

function th-map-set {

  @include th-assert(
    $describe: "Set map key 'foo' to 'Hello World'"
  ){
    @include th-assert-expect {
      result: "Hello World";
    }
    @include th-assert-actual {
      $result: th-map-set((foo: 'First', bar: 'Second'), $key: foo, $value: 'Hello World');
      result: map-get($result, foo);
    }
  }

}

// th-list-has-index()
// ------------------------------

function th-list-has-index {

  @include th-assert(
    $describe: "Check list for an index."
  ){
    @include th-assert-expect {
      result: true;
    }
    @include th-assert-actual {
      result: th-list-has-index( (1, 2, 3), 1 );
    }
  }

  @include th-assert(
    $describe: "Check list for an index."
  ){
    @include th-assert-expect {
      result: false;
    }
    @include th-assert-actual {
      result: th-list-has-index( (1, 2, 3), 4 );
    }
  }

}

// th-list-has()
// ------------------------------

function th-list-has {

  @include th-assert(
    $describe: "Check list for value x (exists)."
  ){
    @include th-assert-expect {
      result: true;
    }
    @include th-assert-actual {
      result: th-list-has( (a, b, x), x );
    }
  }

  @include th-assert(
    $describe: "Check list for value x (doesn't exist)."
  ){
    @include th-assert-expect {
      result: false;
    }
    @include th-assert-actual {
      result: th-list-has( (a, b, c), x );
    }
  }

}

// th-list-has-deep()
// ------------------------------

function th-list-has-deep {

  @include th-assert(
    $describe: "Check list for a value."
  ){
    @include th-assert-expect {
      result: true;
    }
    @include th-assert-actual {
      result: th-list-has-deep( (a, (b, c), d), a);
    }
  }

  @include th-assert(
    $describe: "Check list for a deep value."
  ){
    @include th-assert-expect {
      result: true;
    }
    @include th-assert-actual {
      result: th-list-has-deep( (a, (b, c), d), c);
    }
  }

  @include th-assert(
    $describe: "Check list for a deep value that doesnt exist."
  ){
    @include th-assert-expect {
      result: false;
    }
    @include th-assert-actual {
      result: th-list-has-deep( (a, (b, c), d), e);
    }
  }

}

function th-list-flatten {

  @include th-assert(
  $describe: "Flatten multidimensional list."
  ){
    @include th-assert-expect {
      result: (a, b, c, d);
    }
    @include th-assert-actual {
      result: th-list-flatten((a, b, (c, d)));
    }
  }

}


// th-unit-strip()
// ------------------------------

function th-unit-strip {

  @include th-assert(
    $describe: "Strip unit from 32px."
  ){
    @include th-assert-expect {
      result: 32;
    }
    @include th-assert-actual {
      result: th-unit-strip(32px);
    }
  }

}

// th-unit-cast()
// ------------------------------

function th-unit-cast {

  @include th-assert(
    $describe: "Create a 32px number."
  ){
    @include th-assert-expect {
      result: 32px;
    }
    @include th-assert-actual {
      result: th-unit-cast(32, px);
    }
  }

  @include th-assert(
    $describe: "Create a 32foo number (doesn't exist)."
  ){
    @include th-assert-expect {
      result: 32;
    }
    @include th-assert-actual {
      result: th-unit-cast(32, foo);
    }
  }

}

// th-unit-convert-number()
// ------------------------------

function th-unit-convert {

  @include th-assert(
    $describe: "Bind 32 to em."
  ){
    @include th-assert-expect {
      result: 32em;
    }
    @include th-assert-actual {
      result: th-unit-cast(32, em);
    }
  }

}


// th-unit-convert-absolute()
// ------------------------------

function th-unit-convert-absolute {

  @include th-assert(
    $describe: "Convert 4.889em to px."
  ){
    @include th-assert-expect {
      result: 88.002px;
    }
    @include th-assert-actual {
      result: th-unit-convert-absolute(4.889em, px);
    }
  }

  @include th-assert(
    $describe: "Convert 4.889 to px."
  ){
    @include th-assert-expect {
      result: 88.002px;
    }
    @include th-assert-actual {
      result: th-unit-convert-absolute(4.889, px);
    }
  }

  @include th-assert(
    $describe: "Convert 4.889rem to px."
  ){
    @include th-assert-expect {
      result: 88.002px;
    }
    @include th-assert-actual {
      result: th-unit-convert-absolute(4.889rem, px);
    }
  }

  @include th-assert(
    $describe: "Convert 2.750em to px with base font size of 32px."
  ){
    @include th-assert-expect {
      result: 88px;
    }
    @include th-assert-actual {
      result: th-unit-convert-absolute(2.750em, px, 32px);
    }
  }

}

// th-unit-convert-relative()
// ------------------------------

function th-unit-convert-relative {

  @include th-assert(
    $describe: "Convert 32px to em."
  ){
    @include th-assert-expect {
      result: 1.77778em;
    }
    @include th-assert-actual {
      result: th-unit-convert-relative(32px, em);
    }
  }

  @include th-assert(
    $describe: "Convert 32px to rel."
  ){
    @include th-assert-expect {
      result: 1.77778;
    }
    @include th-assert-actual {
      result: th-unit-convert-relative(32px, false);
    }
  }

  @include th-assert(
    $describe: "Convert 32px to rem."
  ){
    @include th-assert-expect {
      result: 1.77778rem;
    }
    @include th-assert-actual {
      result: th-unit-convert-relative(32px, rem);
    }
  }

  @include th-assert(
    $describe: "Convert 32px to em with base font size of 12px."
  ){
    @include th-assert-expect {
      result: 2.66667em;
    }
    @include th-assert-actual {
      result: th-unit-convert-relative(32px, em, 12px);
    }
  }

}

// _th-unit-convert-em()
// ------------------------------

function th-unit-convert-em {

  @include th-assert(
    $describe: "Convert 22px to em."
  ){
    @include th-assert-expect {
      result: 1.22222em;
    }
    @include th-assert-actual {
      result: th-unit-convert-em(22px);
    }
  }

  @include th-assert(
    $describe: "Convert 24px to em with base font size of 32px."
  ){
    @include th-assert-expect {
      result: 0.75em;
    }
    @include th-assert-actual {
      result: th-unit-convert-em(24px, 32px);
    }
  }

}

// _th-unit-convert-rem()
// ------------------------------

function th-unit-convert-rem {

  @include th-assert(
    $describe: "Convert 22px to rem."
  ){
    @include th-assert-expect {
      result: 0.91667rem;
    }
    @include th-assert-actual {
      result: th-unit-convert-rem(22px);
    }
  }

}

// th-unit-convert-rel()
// ------------------------------

function th-unit-convert-rel {

  @include th-assert(
    $describe: "Convert 22px to rel."
  ){
    @include th-assert-expect {
      result: 1.22222;
    }
    @include th-assert-actual {
      result: th-unit-convert-rel(22px);
    }
  }

  @include th-assert(
    $describe: "Convert 24px to rel with base font size of 32px."
  ){
    @include th-assert-expect {
      result: 0.75;
    }
    @include th-assert-actual {
      result: th-unit-convert-rel(24px, 32px);
    }
  }

}

// th-unit-convert-px()
// ------------------------------

function th-unit-convert-px {

  @include th-assert(
    $describe: "Convert 2.35em to px."
  ){
    @include th-assert-expect {
      result: 42.3px;
    }
    @include th-assert-actual {
      result: th-unit-convert-px(2.35em);
    }
  }

  @include th-assert(
    $describe: "Convert 2.35em to px with base font size of 22px."
  ){
    @include th-assert-expect {
      result: 51.7px;
    }
    @include th-assert-actual {
      result: th-unit-convert-px(2.35em, 22px);
    }
  }

}